(define observed-symbols '())

(define (emit! name)
  (set! observed-symbols (cons name observed-symbols))
  name)

(define (join-symbols name i)
  (string->symbol
   (string-append (symbol->string name)
		  (number->string i))))

(define (gensym* name i)
  (let ((sym (join-symbols name i)))
    (if (member sym observed-symbols)
	(gensym* name (+ i 1))
	(emit! sym))))

(define (gensym name)
  (if (member name observed-symbols)
      (gensym* name 0)
      (emit! name)))


